# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=lua-hashids
pkgver=1.0.6
pkgrel=4
pkgdesc="Lua implementation of hashids"
url="https://github.com/leihog/hashids.lua"
arch="all"
license="MIT"
options="!check"
source="hashids.lua-$pkgver.tar.gz::https://github.com/leihog/hashids.lua/archive/v$pkgver.tar.gz"

builddir="$srcdir"/hashids.lua-$pkgver

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		make -C "$builddir-$lver"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	cd "$builddir-$lver"
	make INSTALLDIR="$subpkgdir"/usr/lib/lua/$lver/hashids install
	mkdir -p "$subpkgdir"/usr/share/lua/$lver/hashids
	mv "$subpkgdir"/usr/lib/lua/$lver/hashids/init.lua \
		"$subpkgdir"/usr/share/lua/$lver/hashids/
}

sha512sums="33ae6d8e465a35bb04a791da645d6003a25d6917a67aaa4abbb5d80470d6ad6b37ff4ed5b82bc4893be2f0dfb213730c13ae1d14486c5476d0b892b64345f2d7  hashids.lua-1.0.6.tar.gz"
